﻿//using System.Linq;

//using System;
////class ExtensionMethods2
////{

////    static void Main()
////    {
////        int[] ints = { 10, 45, 15, 39, 21, 26 };
////        var result = ints.OrderBy(g => g);
////        foreach (var i in result)
////        {
////            System.Console.WriteLine(i + " ");
////        }
////        Console.ReadKey();
////    }
////}
//////Output: 10 15 21 26 39 45
////----------------------------------------------定义和调用扩展方法
//// https://learn.microsoft.com/zh-cn/dotnet/csharp/programming-guide/classes-and-structs/how-to-implement-and-call-a-custom-extension-method?view=azure-dotnet
////namespace CustomExtensions
////{
////    // Extension methods must be defined in a static class.

////    public static class StringExtension
////    {
////        // This is the extension method.
////        // The first parameter takes the "this" modifier
////        // and specifies the type for which the method is defined.

////        //1,定义包含扩展方法的静态类。

////        //2,此类必须对客户端代码可见。 有关可访问性规则的详细信息，请参阅访问修饰符。

////        //3,将扩展方法实现为静态方法，并且使其可见性至少与所在类的可见性相同。

////        //4,此方法的第一个参数指定方法所操作的类型；此参数前面必须加上 this 修饰符。

////        //5, 在调用代码中，添加 using 指令，用于指定包含扩展方法类的命名空间。
////        //  和调用类型的实例方法那样调用这些方法。
////        public static int WordCount(this string str, StringSplitOptions options)
////        {
////            return str.Split(new char[] { ' ', '.', '?' }, options).Length;
////        }
////    }
////}
////namespace Extension_Methods_Simple
////{
////    // Import the extension method namespace.
////    using CustomExtensions;
////    using System.Collections.Generic;

////    class Program
////    {
////        static void Main(string[] args)
////        {
////            string s = "The quick brown fox jumped over the lazy dog.";
////            // Call the method as if it were an
////            // instance method on the type. Note that the first
////            // parameter is not specified by the calling code.
////            int i = s.WordCount(StringSplitOptions.None);
////            System.Console.WriteLine("Word count of s is {0}", i);
////            System.Console.ReadKey();

////        }
////    }
////}

////----------------------------------------------如何为枚举创建新方法（C# 编程指南）
////using System;

////namespace EnumExtension
////{
////    // Define an extension method in a non-nested static class.
////    public static class Extensions
////    {
////        public static Grades minPassing = Grades.D;
////        public static bool Passing(this Grades grade)
////        {
////            return grade >= minPassing;
////        }
////    }

////    public enum Grades { F = 0, D = 1, C = 2, B = 3, A = 4 };
////    class Program
////    {
////        public static void ExampleMethod(int required, string optionalstr = "default string",
////    int optionalint = 10)
////        {
////        }
////        static void Main(string[] args)
////        {
////            Grades g1 = Grades.D;
////            Grades g2 = Grades.F;
////            Console.WriteLine("First {0} a passing grade.", g1.Passing() ? "is" : "is not");
////            Console.WriteLine("Second {0} a passing grade.", g2.Passing() ? "is" : "is not");

////            Extensions.minPassing = Grades.C;
////            Console.WriteLine("\r\nRaising the bar!\r\n");
////            Console.WriteLine("First {0} a passing grade.", g1.Passing() ? "is" : "is not");
////            Console.WriteLine("Second {0} a passing grade.", g2.Passing() ? "is" : "is not");
////        }
////    }
////}
/////* Output:
////    First is a passing grade.
////    Second is not a passing grade.

////    Raising the bar!

////    First is not a passing grade.
////    Second is not a passing grade.
//// */

//namespace IntExpression
//{

//    public static class StrToInt32Class
//    {

//        public static Int32 StrToInt32(this string str)
//        {

//            Int32 result = 0;
//            //result = int.Parse(str);
//            result = Convert.ToInt32(str);

//            return result;
//        }

//    }
//    public class program
//    {
//        public static void Main(string[] args)
//        {
//            string name = "123";
//            Int32 name2 = name.StrToInt32();
//            Console.WriteLine(name2.ToString());
//            Console.ReadKey();

//        }
//    }
//}




